# -*- coding: utf-8 -*-
import psycopg2

import xmlrpclib
from xmlrpclib import DateTime
from xmlrpclib import Binary
import psycopg2.extras
import decimal
from datetime import time,datetime
import datetime as datetime2

schema_proxy_common="http://localhost:8069/xmlrpc/common"
schema_proxy_object="http://localhost:8069/xmlrpc/object"

#destination
db_destination='db_mbt_prod_61_18_12_2012'
utilisateur_openerp='admin'
mot_de_passe_openerp='nimda'

db_source='db_mbt_update_cin'


sock = xmlrpclib.ServerProxy(schema_proxy_common)
uid = sock.login(db_source ,utilisateur_openerp ,mot_de_passe_openerp)
sock = xmlrpclib.ServerProxy(schema_proxy_object)

sock_new = xmlrpclib.ServerProxy(schema_proxy_common)
uid_new = sock_new.login(db_source ,utilisateur_openerp ,mot_de_passe_openerp)
sock_new = xmlrpclib.ServerProxy(schema_proxy_object)


ids=sock.execute(db_source, uid, mot_de_passe_openerp, 'hr.employee', "search",[])

for data_read in sock.execute(db_source, uid, mot_de_passe_openerp, 'hr.employee', "read",ids,['cin','matricule','name','children','date','anciennete','compte','mode_reglement','bank']) :
    print "data_read"
    print data_read
    data_write={
                    'cin' : data_read['cin'],
                    'matricule' : data_read['matricule'],
                    'children' : data_read['children'],
                    'date' : data_read['date'],
                    'anciennete' : data_read['anciennete'],
                    'compte' : data_read['compte'],
                    'mode_reglement' : data_read['mode_reglement'],
                    'bank' : data_read['bank'],
                    }
    
    ids_co = sock_new.execute(db_destination, uid, mot_de_passe_openerp, 'hr.employee', "search",[('name','=',data_read['name'])])
    if ids_co:
        print "correspondance"
        print ids_co 
        sock_new.execute(db_destination, uid, mot_de_passe_openerp, 'hr.employee', "write",ids_co,data_write)
